const jwt = require('jsonwebtoken')

function sign(option){
  return jwt.sign(option,'bilibili',{
    expiresIn:'1h'
  })
}

let verify = () =>(ctx,next) =>{
  let jwtToken = ctx.request.header.authorization
  if(jwtToken){
    jwt.verify(jwtToken,'666',function(err,decoded){
      if(err){
        ctx.status = 401
        ctx.body ={
          code:'1',
          msg:'账号登录失效'
        }
      }
    })
  }
}


module.exports ={
  sign,
  verify
}